#!/usr/bin/env perl
# CGI script for checking if a page is up.

print "Content-Type: text/html\n\n";

print "<!DOCTYPE html>";
print "<html>";
print "<head>";
print "<title>";
$URL="";
if($ENV{QUERY_STRING} eq "") {
print "Down For Everyone Or Just Me? - Thanks Microsoft";
}
else {
$PARSINGCOMPLETE=false;
@charlist=split(//, $ENV{QUERY_STRING});
foreach $char (@charlist) {
if($PARSINGCOMPLETE eq "true") {
$URL .= $char;
}
if ($char eq "=") {
$PARSINGCOMPLETE=true;
}
}
$URL=`bash process-url.sh "$URL"`;
print "Is ",$URL, " down for everyone or just me? - Thanks Microsoft";
}
print "</title>";
print "</head>";
print "<body>";
if($ENV{QUERY_STRING} ne "")
{
if(`bash -c 'wget -q -O /dev/null '$URL' && echo -n Success'` ne "Success") {
print "<h1>It's not just you!</h1>";
print '<h2 style="font-weight: 400">', $URL, " seems down from here.</h2>";
}
else {
print "<h1>It's just you.</h1>";
print '<h2 style="font-weight: 400">', $URL, " seems up from here.</h2>"
}
}
else {
print '<form action="/" method="get">';
print '<h2 style="font-weight: 400">', "Is ";
print '<input type="text" name="url" />';
print " down for everyone or just me? ", '<input type="submit" value="Check" />',  "</h2></form>";
}
print "</body>";
print "</html>"
